Overloading a method with parameter Func

No, that approach wouldn't work. You'd be trying to pass a Func(Func func, string cacheKey) { // Do real stuff in here // You may find ConcurrentDictionary helpful... } public static TResult PerformCaching (Func func, T1 first, string cacheKey) { return PerformCaching(() => func(first), cacheKey); } public static TResult PerformCaching (Func func, T1 first, T2 second, string cacheKey) { return PerformCaching(() => func(first, second), cacheKey); } public static TResult PerformCaching (Func func, T1 first, T2 second, T3 third, string cacheKey) { return PerformCaching(() => func(first, second, third), cacheKey); }.

No, that approach wouldn't work. You'd be trying to pass a Func to a method accepting a Func - and that simply doesn't work. I would suggest changing to something like this: public static TResult PerformCaching(Func func, string cacheKey) { // Do real stuff in here // You may find ConcurrentDictionary helpful... } public static TResult PerformCaching (Func func, T1 first, string cacheKey) { return PerformCaching(() => func(first), cacheKey); } public static TResult PerformCaching (Func func, T1 first, T2 second, string cacheKey) { return PerformCaching(() => func(first, second), cacheKey); } public static TResult PerformCaching (Func func, T1 first, T2 second, T3 third, string cacheKey) { return PerformCaching(() => func(first, second, third), cacheKey); }.

Thanks Jon, this works like a charm. I was thinking in the wrong order of calling the methods. – ChristiaanV May 23 at 11:49.

You have to project from Func to Func. It's not hard but I'm not sure this is the best approach. You also have other generic issues, like casting to Model (which I converted to string).

A better approach would likely be something like Cache. Retrieve(string cashKey, Func missingItemFactory). Then you would call like Cache.

Retrieve("model1", () => repository. Get(myId)) then just call if (data == null) data = missingItemFactory(); inside your method. Regardless, a solution is below.

Void Main() { Func f1 = s => "One"; Func f2 = (s1, s2) => "Two"; Func f3 = (s1, s2, s3) => "Three"; Console. WriteLine(PerformCaching(f1, "one", "f1")); Console. WriteLine(PerformCaching(f1, "one", "f1")); Console.

WriteLine(PerformCaching(f2, "one", "two", "f2")); Console. WriteLine(PerformCaching(f2, "one", "two", "f2")); Console. WriteLine(PerformCaching(f3, "one", "two", "three", "f3")); Console.

WriteLine(PerformCaching(f3, "one", "two", "three", "f3")); } // Define other methods and classes here public static TResult PerformCaching(Func func, T1 first, string cacheKey) { return PerformCaching((t, t2, t3) => func(t), first, null, null, cacheKey); } public static TResult PerformCaching(Func func, T1 first, T2 second, string cacheKey) { return PerformCaching((t, t2, t3) => func(t, t2), first, second, null, cacheKey); } public static TResult PerformCaching(Func func, T1 first, T2 second, T3 third, string cacheKey) { TResult data = Get(cacheKey); if(data == null) { Add(cacheKey); data = func. Invoke(first, second, third); Update(data); } return data; } public static T Get(string CashKey) { return default(T); } public static void Add(string CashKey) { } public static void Update(T data) { }.

Get(myId)) then just call if (data == null) data = missingItemFactory(); inside your method. Regardless, a solution is below.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.